from Base.base import Base
from selenium.webdriver.common.by import By
import time
from Data.data import db

sql = db('root','yidong666','10.59.9.12','a3mall')

class Page(Base):
    #定位器
    # 请登录

    # 账号定位元素
    username_loc = (By.NAME,'username')
    # 密码定位元素
    password_loc = (By.NAME,'password')
    # 登录按钮元素
    login_btn_loc = (By.CLASS_NAME,'finish-btn')

    # 方法封装
    # 请登录
    login_loc = (By.LINK_TEXT, '登录')
    def login(self):
        self.click(self.login_loc)

    userlogin_loc=(By.CLASS_NAME,'reg-new')
    def userlogintext(self):
        return self.text(self.userlogin_loc)

    uname_loc=(By.NAME,'username')
    # 输入账号密码
    def username(self,username):
        self.send_keys(self.uname_loc,username)

    pwd_loc = (By.NAME, 'password')
    def password(self,password):
        self.send_keys(self.pwd_loc,password)


    logintotal_loc = (By.XPATH, '/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]')
    def logintotal(self):
        return self.text(self.logintotal_loc)

    # 点击登录按钮
    btn_loc = (By.CLASS_NAME, 'finish-btn')
    def login_btn(self):
        self.click(self.login_btn_loc)

    #登录成功断言数据库
    ye = sql.select('select amount from mall_users where username = "13811033962"')
    print(ye[0][0])
    sjk_loc = (By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]/span')
    def sjk(self):
        return self.text(self.sjk_loc)

    #点击首页
    sy_loc = (By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    def sy(self):
        self.click(self.sy_loc)

    sp_loc = (By.XPATH,'/html/body/div[7]/div/div[2]/div[2]/div[2]/div[2]/span[2]/a')
    def sp(self):
        self.click(self.sp_loc)

    buy_loc = (By.ID,'buy-cart')
    def buy(self):
        self.click(self.buy_loc)

    adress_loc = (By.ID,'address-14')
    def adress(self):
        self.click(self.adress_loc)

    xyb_loc = (By.ID,'order-button')
    def xyb(self):
        self.click(self.xyb_loc)

    ckdd_loc = (By.XPATH,'/html/body/div[4]/div[3]/p/a')
    def ckdd(self):
        self.click(self.ckdd_loc)

    # 业务逻辑
    def luoji_A3mall(self,password,username):
        self.open_url('http://10.59.9.12:7001/')
        #鼠标单击
        self.sbclick(self.login_loc)

        time.sleep(3)
        print("断言：会员登录",self.userlogintext())
        self.username(username)
        self.password(password)
        time.sleep(6)
        self.login_btn()
        time.sleep(10)
        self.logintotal()
        # print("断言：欢饮回来",self.logintotal())
